package android.slc.appbase.ui.vd;

import cn.hutool.core.collection.CollectionUtil;
import javafx.application.Platform;
import javafx.scene.control.ListView;

import java.io.Serializable;
import java.util.List;

/**
 * 基础的单次加载盒子vm
 *
 * @author slc
 * @date 2020-08-25 16:13
 */
public abstract class BaseListViewVd<T extends Serializable, VB extends BaseListVmBox<T>> extends BaseListVd<T, VB> {

    protected ListView<T> listView;

    @Override
    protected void initSwipeRecycler() {
        super.initSwipeRecycler();
        this.listView = (ListView<T>) contentView.lookup(getListViewId());
    }

    protected String getListViewId() {
        return "#listView";
    }

    @Override
    protected void notifyRecyclerRefresh(List<T> list) {
        super.notifyRecyclerRefresh(list);
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                if (CollectionUtil.isEmpty(list)) {
                    BaseListViewVd.this.listView.getItems().clear();
                } else {
                    BaseListViewVd.this.listView.getItems().setAll(list);
                }
            }
        });
    }

}
